﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADONETDataServicesExtension.Providers;
using ADONETDataServicesExtension.Utils;

namespace ADONETDataServicesExtension
{
    public class SegmentInfo : FrameworkEncapsulatedType<object>
    {
        internal const string FrameworkTypeName = "System.Data.Services.SegmentInfo";

        public SegmentInfo(object segmentInfo)
            : base(segmentInfo)
        {
        }

        public int TargetKind
        {
            get
            {
                return ReflectionHelper.GetProperty<int>(FrameworkTypeName, "TargetKind", FrameworkObject);
            }
            set
            {
                ReflectionHelper.SetProperty(FrameworkTypeName, "TargetKind", FrameworkObject, value);
            }
        }

        public ServiceOperation Operation
        {
            get
            {
                return ReflectionHelper.Convert(ReflectionHelper.GetProperty(FrameworkTypeName, "Operation", FrameworkObject), frameworkValue => new ServiceOperation(frameworkValue));
            }
            set
            {
                ReflectionHelper.SetProperty(FrameworkTypeName, "Operation", FrameworkObject, value == null ? null : value.FrameworkObject);
            }
        }

        public object[] OperationParameters
        {
            get
            {
                return ReflectionHelper.GetProperty<object[]>(FrameworkTypeName, "OperationParameters", FrameworkObject);
            }
            set
            {
                ReflectionHelper.SetProperty(FrameworkTypeName, "OperationParameters", FrameworkObject, value);
            }
        }

        public int TargetSource
        {
            get
            {
                return ReflectionHelper.GetProperty<int>(FrameworkTypeName, "TargetSource", FrameworkObject);
            }
            set
            {
                ReflectionHelper.SetProperty(FrameworkTypeName, "TargetSource", FrameworkObject, value);
            }
        }

        public ResourceProperty ProjectedProperty
        {
            get
            {
                return ReflectionHelper.Convert(ReflectionHelper.GetProperty(FrameworkTypeName, "ProjectedProperty", FrameworkObject), frameworkValue => new ResourceProperty(frameworkValue));
            }
            set
            {
                ReflectionHelper.SetProperty(FrameworkTypeName, "ProjectedProperty", FrameworkObject, value == null ? null : value.FrameworkObject);
            }
        }

        public string Identifier
        {
            get
            {
                return ReflectionHelper.GetProperty<string>(FrameworkTypeName, "Identifier", FrameworkObject);
            }
            set
            {
                ReflectionHelper.SetProperty(FrameworkTypeName, "Identifier", FrameworkObject, value);
            }
        }

        public KeyInstance Key
        {
            get
            {
                return ReflectionHelper.Convert(ReflectionHelper.GetProperty(FrameworkTypeName, "Key", FrameworkObject), frameworkValue => new KeyInstance(frameworkValue));
            }
        }

        public Type TargetElementType
        {
            get
            {
                return ReflectionHelper.GetProperty<Type>(FrameworkTypeName, "TargetElementType", FrameworkObject);
            }
        }
    }
}
